package com.qifei.xmlg_backend.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qifei.xmlg_backend.DTO.announcement.AnnouncementQueryParam;
import com.qifei.xmlg_backend.entity.Announcement;
import com.qifei.xmlg_backend.entity.PageBean;
import com.qifei.xmlg_backend.mapper.AnnouncementMapper;
import com.qifei.xmlg_backend.service.IAnnouncementService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author announcement
 * @since 2025-06-20
 */
@Service
@Slf4j
public class AnnouncementServiceImpl extends ServiceImpl<AnnouncementMapper, Announcement> implements IAnnouncementService {

    private final AnnouncementMapper announcementMapper;

    public AnnouncementServiceImpl(AnnouncementMapper announcementMapper) {
        this.announcementMapper = announcementMapper;
    }

    @Override
    public PageBean<Announcement> getAnnouncementList(AnnouncementQueryParam param) {
        Page<Announcement> page = new Page<>(param.getPage(), param.getPageSize());

        IPage<Announcement> result = announcementMapper.selectPageVo(
                page,
                param.getTitle(),
                param.getAuthor(),
                param.getStatus(),
                param.getBegin(),
                param.getEnd()
        );

        return new PageBean<>(result.getTotal(), result.getRecords());


   }

}
